package com.cskaoyan.service;

import com.cskaoyan.bean.entity.Permission;
import com.cskaoyan.bean.entity.PermissionExample;
import com.cskaoyan.mapper.PermissionMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @author XuBang
 * @TODO:
 * @date 2021/10/21$
 * @trainOfthought:
 */
@Service
public class AuthServicelmpl implements AuthService{
    @Autowired
    PermissionMapper permissionMapper;

    //根据id判断：if(id==5) 在permisssion中查询role_id=2，对应的permission   mall
    @Override
    public List<String> infoMall(int i) {

        //1.构造条件
        PermissionExample example = new PermissionExample();
        PermissionExample.Criteria criteria = example.createCriteria();
        criteria.andRoleIdEqualTo(i);

        //2.查询返回
        List<Permission> permissions = permissionMapper.selectByExample(example);

        //3.处理提取其中的url部分
        ArrayList<String> permiss = new ArrayList<>();
        for (Permission permission : permissions) {
            permiss.add(permission.getPermission());
        }
        return permiss;
    }

    //根据id判断：if(id==4) 在permisssion中查询role_id=3，对应的permission   promotion
    @Override
    public List<String> infoPromo(int i) {
        //1.构造条件
        PermissionExample example = new PermissionExample();
        PermissionExample.Criteria criteria = example.createCriteria();
        criteria.andRoleIdEqualTo(i);

        //2.查询返回
        List<Permission> permissions = permissionMapper.selectByExample(example);

        //3.处理提取其中的url部分
        ArrayList<String> permiss = new ArrayList<>();
        for (Permission permission : permissions) {
            permiss.add(permission.getPermission());
        }
        return permiss;
    }
}
